import java.util.LinkedList;
import java.util.Queue;
//用链表实现队列
class MyQueue{
    static class ListNode{
        public int val;
        public ListNode prev;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;
        }
    }
    public  ListNode head;
    public  ListNode last;
public void offer(int val){
    ListNode listNode=new ListNode(val);
    if (head==null){
        head=last=listNode;
    }
    else {
        last.next=listNode;
        listNode.prev=last;
        last=listNode;
    }
}

public int  poll(){
    if (head==null){
        return -1;
    }
    int ret=head.val;
    if (head.next==null){
        head=last=null;
    }else {
        head.next.prev = null;
        head = head.next;
    }
    return ret;
}
public int peek(){
    if (head==null){
        return -1;
    }
    return head.val;
}
public boolean isEmpty(){
    return head==null;
}
}
public class Text2 {
    public static void main(String[] args) {
        MyQueue myQueue = new MyQueue();
        myQueue.offer(1);
        myQueue.offer(2);
        myQueue.offer(3);
        myQueue.offer(4);
        myQueue.offer(5);//增加//尾差法
        System.out.println(myQueue.poll());//出队//头删法
        System.out.println(myQueue.peek());
        System.out.println(myQueue.isEmpty());
    }
}
